//
//  ZXFDXuanZeZiYuanCellTableViewCell.m
//  SanYiTeaching
//
//  Created by 李文强 on 2019/4/22.
//  Copyright © 2019 SanYi. All rights reserved.
//

#import "ZXFDXuanZeZiYuanCellTableViewCell.h"

@implementation ZXFDXuanZeZiYuanCellTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self initSubView];
        [self layout];
    }
    return self;
}
- (void)initSubView{
    [self addSubview:self.baseView];
    [_baseView addSubview:self.leftImageView];
    [_baseView addSubview:self.titleLabel];
    [_baseView addSubview:self.sizeLabel];
    [_baseView addSubview:self.timeLabel];
    [_baseView addSubview:self.selectedButton];
}
- (void)layout{
    [_baseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@60);
        make.centerY.equalTo(self.mas_centerY);
        make.right.equalTo(@0).offset(-60);
        make.height.equalTo(@50);
    }];
    [_leftImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@10);
        make.centerY.equalTo(self.mas_centerY);
        make.width.equalTo(@30);
        make.height.equalTo(@30);
    }];
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self->_leftImageView.mas_right).offset(10);
        make.top.equalTo(@10);
        make.width.equalTo(@60);
        make.height.equalTo(@15);
    }];
    [_sizeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self->_titleLabel.mas_left);
        make.bottom.equalTo(self->_baseView.mas_bottom).offset(-10);
        make.width.equalTo(@40);
        make.height.equalTo(@15);
    }];
    [_timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self->_baseView.mas_right).offset(-30);
        make.centerY.equalTo(self.mas_centerY);
        make.width.equalTo(@120);
        make.height.equalTo(@20);
    }];
    [_selectedButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self->_baseView.mas_right).offset(-10);
        make.centerY.equalTo(self.mas_centerY);
        make.width.equalTo(@15);
        make.height.equalTo(@15);
    }];
}
- (UIButton *)selectedButton{
    if (!_selectedButton) {
        UIButton *button = [UIButton buttonWithType: UIButtonTypeCustom];
        [button setBackgroundImage:[UIImage imageNamed:@"selecSquir"] forState:UIControlStateSelected];
        [button setBackgroundImage:[UIImage imageNamed:@"yj_xuanze_noxues"] forState:UIControlStateNormal];
        button.selected = NO;
        [button addTarget:self action:@selector(selectedClick:) forControlEvents:UIControlEventTouchUpInside];
        _selectedButton = button;
    }
    return _selectedButton;
}
- (void)selectedClick:(UIButton *)sender{
    sender.selected = !sender.selected;
    if (sender.selected == YES ) {
        self.selcetedBlock(_zyID);
    }else{
        self.noSelcetedBlock(_zyID);
    }
}
- (UIView *)baseView{
    if (!_baseView) {
        UIView *view = [[UIView alloc]init];
        _baseView = view;
    }
    return _baseView;
}
- (UIImageView *)leftImageView{
    if (!_leftImageView) {
        UIImageView *leftImageView = [[UIImageView alloc]init];
        _leftImageView = leftImageView;
    }
    return _leftImageView;
}
- (UILabel *)titleLabel{
    if (!_titleLabel) {
        UILabel *label = [[UILabel alloc]init];
        label.textColor = TITLECOLOR;
        label.font = [UIFont systemFontOfSize:13];
        label.textAlignment = 0;
        _titleLabel = label;
    }
    return _titleLabel;
}
- (UILabel *)sizeLabel{
    if (!_sizeLabel) {
        UILabel *label = [[UILabel alloc]init];
        label.textColor = TITLECOLOR;
        label.font = [UIFont systemFontOfSize:13];
        label.textAlignment = 0;
        _sizeLabel = label;
    }
    return _sizeLabel;
}
- (UILabel *)timeLabel{
    if (!_timeLabel) {
        UILabel *label = [[UILabel alloc]init];
        label.textColor = TITLECOLOR;
        label.font = [UIFont systemFontOfSize:13];
        label.textAlignment = 0;
        _timeLabel = label;
    }
    return _timeLabel;
}
@end
